﻿
package export.monster
{
    
    
    import base.BaseMonster;
    
    import com.game.data.constant.FrameRate;
    
    import com.game.engine.MainGame;
    import com.game.manager.AnimationManager;
    import com.greensock.TweenMax;
    
    import export.bullet.EnemyMoveBullet;
    
    import export.bullet.RegionBullet;
    
    import flash.geom.Rectangle;
    
    public class Monster306 extends BaseMonster
    {

        private var isFirstLowHp:Boolean = true;
        private var baby:Monster307;
        //鲨魔王

        public function Monster306()
        {
            super();
        }
        
        override protected function initBBDC():void
        {
            bbdc = AnimationManager.getAnimation("Monster306Action");
            bbdc.setAction("idle");
            bbdc.turnRight();
            bbdc.addCallBack(onEnterFrame, onActionOver);
            bodyContainer.addChild(bbdc);
        }
        
        override protected function initCollideArea():void
        {
            collideBox = new Rectangle(-40,-115,80,115);
            super.initCollideArea();
        }
        
        override protected function initAttribute():void
        {
            super.initAttribute();
            mavo.attackRange = 150;
        }
        
        override protected function beforeSkill1Start():Boolean
        {
            return hasTarget() && AUtils.GetDisBetweenTwoObj(this,curAttackTarget) < 500;
        }
        
        override protected function beforeSkill2Start():Boolean
        {
            return hasTarget();
        }
        
        override protected function onEnterFrame(action:String, frameCount:int):void
        {
            switch (action)
            {
                case "attack1":
                    if(frameCount == 4)
                    {
                        var b:RegionBullet = new RegionBullet();
                        b.setOwner(this);
                        b.setHurt(getActionHurt("attack1"));
                        b.setDirect(bbdc.getDirect());
                        b.setCollideArea(0,-275,320 * bbdc.getDirect(),275);
                        b.setAction("Monster306Attack1");
                        b.setDestroyInCount(4);
                        gc.gameScene.addChild(b);
                        magicBulletArray.push(b);
                    }
                    break;
                case "skill1":
                    if(frameCount == 14)
                    {
                        setInvincible(0.8 * FrameRate.ANIMATE_FRAME_RATE);
                        var bb:EnemyMoveBullet = new EnemyMoveBullet("Monster306Bullet1");
                        bb.setOwner(this);
                        bb.setPosition(getCollideCenter().x,getCollideCenter().y);
                        bb.setDirect(bbdc.getDirect());
                        bb.setHurt(getActionHurt("skill1"));
                        bb.setAction("Monster306Skill1");
                        bb.setDistance(1000);
                        bb.setSpeed(50 * bbdc.getDirect(), 0);
                        gc.gameScene.addChild(bb);
                        magicBulletArray.push(bb);
                    }
                    break;
                case "skill2":
                    if(frameCount == 15)
                    {
                        setInvincible(0.8 * FrameRate.ANIMATE_FRAME_RATE);
                        var bb:EnemyMoveBullet = new EnemyMoveBullet("Monster306Bullet2");
                        bb.setOwner(this);
                        bb.setPosition(hasTarget() ? curAttackTarget.getCollideCenter().x - 100 : x,
                                hasTarget() ? curAttackTarget.getCollideCenter().y - 100 : y);
                        bb.setHurt(getActionHurt("skill2"));
                        bb.setAction("Monster306Skill2");
                        bb.setDisable();
                        TweenMax.delayedCall(2,bb.setEnable);
                        bb.setIsDestroyWhenLastFrame(true);
                        gc.gameScene.addChild(bb);
                        magicBulletArray.push(bb);
                    }
                    break;
                case "dead":
                    if(frameCount == 4)
                    {
                        setInvincible(10 * FrameRate.ANIMATE_FRAME_RATE);
                        var bb:EnemyMoveBullet = new EnemyMoveBullet("Monster306Bullet2");
                        bb.setOwner(this);
                        bb.setPosition(hasTarget() ? curAttackTarget.getCollideCenter().x - 100 : x,
                                hasTarget() ? curAttackTarget.getCollideCenter().y - 100 : y);
                        bb.setHurt(99999999);
                        bb.setAction("Monster306Dead");
                        bb.setDisable();
                        TweenMax.delayedCall(2,bb.setEnable);
                        bb.setIsDestroyWhenLastFrame(true);
                        gc.gameScene.addChild(bb);
                        magicBulletArray.push(bb);
                    }
            }
        }

        override protected function myIntelligence():void
        {
            if (!isBeAttacking())
            {
                super.myIntelligence();
            }
            if (isFirstLowHp)
            {
                if (isLowHp())
                {
//                    baby = MainGame.getIns().createMonster(307, x, y) as Monster307;
                    isFirstLowHp = false;
                }
            }
        }

        private function isLowHp():Boolean
        {
            return getHp() < getHpMax() * 0.65;
        }

        override public function destroy():void
        {
            super.destroy();
            if (baby)
            {
                baby.destroy();
            }
        }
    }
}